home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / rbbs_pc / mnt_201.zip / DUMPOLD.C < prev    next >
Text File  |  1992-01-05  |  7KB  |  183 lines

  1. /****************************************************************************/
  2. /* DUMPOLD module for RBBSMNT v2.01, a maintenance utility for RBBS-PC      */
  3. /*╒═════════════════════════════ NOTICE ═══════════════════════════════════╕*/
  4. /*│  A limited license is granted to all users of this program to make     │*/
  5. /*│  copies if this program and distribute those copies to other users     │*/
  6. /*│  on the following three conditions:                                    │*/
  7. /*│                                                                        │*/
  8. /*│    1.   This notice is NOT altered, bypassed or removed,               │*/
  9. /*│    2.   The program is not to be distributed to others in modified     │*/
  10. /*│         form. You may make changes for your own non-commercial use     │*/
  11. /*│    3.   No fee is to be charged (or any other consideration received)  │*/
  12. /*│         for copying or distributing these programs without an express  │*/
  13. /*│         written agreement with J. Terpstra, Bamestra RBBS, PO Box 66,  │*/
  14. /*│         Beemster, The Netherlands.                                     │*/
  15. /*│                                                                        │*/
  16. /*│Copyright (C) 1991, 1992 - Jan Terpstra, Bamestra RBBS, The Netherlands.│*/
  17. /*╘════════════════════════════════════════════════════════════════════════╛*/
  18. /****************************************************************************/
  19.  
  20. #include "rbbsmnt.h"                    /* definitions for this program     */
  21. #include "externs.h"                    /* external data references         */
  22.  
  23.   /**************************************************************************/
  24.   /* dump old messages to an archive file                                   */
  25.   /**************************************************************************/
  26.  
  27. void dump_old(int msg)
  28. {
  29.    RBBSMSG far *m;
  30.    char far *buf,*q,*r;
  31.    int old,dcount,scount;
  32.    size_t bufsize;
  33.    char *p,oldfile[_MAX_PATH];
  34.    char *ds;
  35.  
  36.    scount = 0;
  37.    strcpy(oldfile, msgfile);
  38.  
  39.    if ((p = strrchr(oldfile, '.')) == NULL)
  40.    {
  41.       p = oldfile+strlen(oldfile);
  42.    }
  43.    sprintf(p, ".%03d", today->tm_yday);
  44.  
  45.    if ((old = open(oldfile, O_CREAT|O_APPEND|O_WRONLY|O_TEXT, S_IREAD|
  46.    S_IWRITE)) == ERROR)
  47.    {
  48.       sprintf(logbuf, "Error opening %s.", oldfile);
  49.       writelog(logbuf, 1, 0);
  50.       return ;
  51.    }
  52.    printf("\r\33[K  Archiving old msgs");
  53.  
  54.    if (p = strstr(oldfile, "M."))
  55.    {
  56.       *p = '\0';
  57.    }
  58.  
  59.    if (p = strrchr(oldfile, '\\'))
  60.    {
  61.       p++;
  62.    }
  63.  
  64.    else
  65.    {
  66.       p = oldfile;
  67.    }
  68.    ds = asctime(today);
  69.    sprintf(logbuf, PRGNAME VERSION
  70.    " Message archive for %s conference, %.2s %.3s %.4s (#%03d)", p, ds+8, ds
  71.    +4, ds+20, today->tm_yday);
  72.    write(old, logbuf, strlen(logbuf));  /* write brag line                  */
  73.  
  74.    /*************************************************************************/
  75.    /* write the messages to a file                                          */
  76.    /*************************************************************************/
  77.  
  78.  
  79.    for (dcount = 0; dcount < lives; dcount++)
  80.    {
  81.  
  82.       if (mlist[dcount].old_num == -1)  /* msg to kill?                     */
  83.       {
  84.  
  85.          if ((scount++%32) == 0)
  86.          {
  87.             printf(".");
  88.          }
  89.          bufsize = mlist[dcount].num_recs *128;/* size of buffer            */
  90.  
  91.          if ((buf = (char far *)malloc(bufsize *sizeof(char))) == NULL)
  92.          {
  93.             sprintf(logbuf, "%s messages buffer.", no_memory);
  94.             writelog(logbuf, 1, 0);
  95.             return ;
  96.          }
  97.          lseek(msg, mlist[dcount].msg_pos, SEEK_SET);/* seek to msg         */
  98.          read(msg, buf, bufsize);       /* read msg                         */
  99.  
  100.          /*******************************************************************/
  101.          /* trim padded spaces from msg text                                */
  102.          /*******************************************************************/
  103.  
  104.          q = buf+bufsize-1;
  105.  
  106.          while ((*q&0x7F) <= ' ')
  107.          {
  108.             *(q--) = '\0';
  109.          }
  110.  
  111.          /*******************************************************************/
  112.          /* build & write separator line                                    */
  113.          /*******************************************************************/
  114.  
  115.          m = (RBBSMSG *)buf;
  116.          memset(logbuf, '\0', 128);
  117.          memset(logbuf, '\n', 1);
  118.          memset(logbuf+1, '-', 72);
  119.          write(old, logbuf, strlen(logbuf));/* write                        */
  120.  
  121.          /*******************************************************************/
  122.          /* build & write Date/To/From/Subj line                            */
  123.          /*******************************************************************/
  124.  
  125.          sprintf(logbuf,
  126.       "\nDate: %8.8s, %8.8s\nFrom: %31.31s\nTo:   %22.22s\nSubj: %25.25s\n\n"
  127.          , m->enter_date, m->enter_time, m->msg_from, m->msg_to, m->msg_subj
  128.          );
  129.          write(old, logbuf, strlen(logbuf));/* write                        */
  130.  
  131.          /*******************************************************************/
  132.          /* translate RBBSCR to regular LF                                  */
  133.          /*******************************************************************/
  134.  
  135.          q = &buf[128];
  136.  
  137.          while (q = strchr(q, 227))
  138.          {
  139.             *q = '\n';
  140.             q++;
  141.          }
  142.  
  143.          /*******************************************************************/
  144.          /* zap kludge lines                                                */
  145.          /*******************************************************************/
  146.  
  147.  
  148.          while (buf[128] == '\x001')
  149.          {
  150.             r = strchr(&buf[128], '\n');
  151.             memmove(&buf[128], ++r, strlen(r)+1);
  152.          }
  153.  
  154.          if ((q = strstr(&buf[128], "\nSEEN-BY:")) || (q = strstr(&buf[128],
  155.          "\n\x001")))
  156.          {
  157.  
  158.             do
  159.             {
  160.                r = strchr(++q, '\n');
  161.                memmove(q, ++r, strlen(r)+1);
  162.             }
  163.  
  164.             while ((q = strstr(&buf[128], "\nSEEN-BY:")) || (q = strstr(&buf
  165.             [128], "\n\x001")));
  166.          }
  167.  
  168.          /*******************************************************************/
  169.          /* write the converted msg text                                    */
  170.          /*******************************************************************/
  171.  
  172.          write(old, &buf[128], strlen(&buf[128]));
  173.          free(buf);
  174.       }
  175.    }
  176.    close(old);
  177.    printf("\r\33[K");
  178. }
  179.  
  180.  
  181. /*--------------------------------------------------------------------------*/
  182.  
  183.